package cn.yeamin.spring.boot.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @packageName: 包名: cn.yeamin.spring.boot.controller
 * @classDesc: 类功能描述:(使用Thymeleaf)
 * @author: Administrator
 * @createTime: 2017/7/18 14:15
 * @version: v1.0
 * @copyright:奕明(上海)影视传媒有限公司
 */
@Controller
public class IndexController {

    /**
     * @methodDesc: 方法描述:(@ResponseBody将返回对象序列化成JSON字符串返回)
     * @author: 李彤
     * @version: v1.0
     * @copyright:奕明(上海)影视传媒有限公司
     */
    @ResponseBody
    @RequestMapping("/index")
    public String hello() {
        return "Index";
    }

    /**
     * @methodDesc: 方法描述:(ModelMap只是给视图设置模型数据,并不做页面跳转)
     * @author: 李彤
     * @version: v1.0
     * @copyright:奕明(上海)影视传媒有限公司
     */
    @ApiOperation(value="跳转到首页", notes="跳转到首页")
    @RequestMapping("/")
    public String index(ModelMap map) {
        map.addAttribute("host", "李彤");
        return "index";
    }

    /**
     * @methodDesc: 方法描述:(ModelAndView不仅给视图设置模型数据,还做页面跳转)
     * @author: 李彤
     * @version: v1.0
     * @copyright:奕明(上海)影视传媒有限公司
     */
    @ApiIgnore  //忽略该接口构建Rest API文档
    @RequestMapping("/mv")
    public ModelAndView indexMv() {
        ModelAndView mv = new ModelAndView("index");
        mv.addObject("host", "李彤MV");
        return mv;
    }


    /**
     * 练习AngularJS
     * @param map
     * @return
     */
    @GetMapping("/al")
    public String get(ModelMap map) {
        return "angular/get";
    }

    /**
     *
     * @param map
     * @return
     */
    @GetMapping("/u")
    @ResponseBody
    public Map<String, Object> getUser(ModelMap map)
    {
        Map<String, Object> user = new LinkedHashMap<String, Object>();
        user.put("name","litong");
        user.put("age",25);
        List list = new ArrayList();
        list.add("java");
        list.add("node.js");
        list.add("php");
        list.add("spark");
        user.put("skills",list);
        return user;
    }






}
